using Moq;
using NUnit.Framework;
using Tycho.Parser.Peg;

namespace Tycho.Parser.Tests.Peg {
    [TestFixture]
    public class CompositeTermFactorySpecification {
        [Test]
        public void ShouldCreateInfixCompositeTerm () {
            var factory = new CompositeTermFactory ();
            var sinfo = new SourceInformation ("filename", 0, 1);
            var precedence = new Mock<IPrecedence> ().Object;
            CompositeTerm term = factory.CreateInfixCompositeTerm ("name", precedence, "first", "last", sinfo);
            var infixTerm = (InfixCompositeTerm) term;

            Assert.That (infixTerm.Name, Is.EqualTo ("name"));
            Assert.That (infixTerm.FirstName, Is.EqualTo ("first"));
            Assert.That (infixTerm.LastName, Is.EqualTo ("last"));
            Assert.That (infixTerm.SourceInformation, Is.SameAs (sinfo));
            Assert.That (infixTerm.Precedence, Is.SameAs (precedence));
        }

        [Test]
        public void ShouldCreateCompositeTerm () {
            var factory = new CompositeTermFactory ();
            var sinfo = new SourceInformation ("filename", 0, 1);
            CompositeTerm term = factory.CreateCompositeTerm ("name", sinfo);

            Assert.That (term.Name, Is.EqualTo ("name"));
            Assert.That (term.SourceInformation, Is.SameAs (sinfo));
        }
    }
}